class PrintChar {
    constructor(char, times) {
        if (char === undefined || typeof char !== "string") throw "the first parameter should be a string!";
        if (times === undefined || typeof times !== "number") throw "the second parameter should be a number!";
        
        this.char = char;
        this.times = times;
    }
    for1() {
        for (let i = 0; i < this.times; i++) {
            let length = i + 1,
                res = "";
            for (let j = 0; j < length; j++) {
                res += this.char;
            }
            console.log(res);
        }
    }

    for2() {
        for (let i = 0; i < this.times; i++) {
            let length = this.times - i,
                res = "";
            for (let j = 0; j < length; j++) {
                res += this.char;
            }
            console.log(res);
        }
    }

    for3() {
        for (let i = 0; i < this.times; i++) {
            let length = this.times - i,
                res = "";
            if (length % 2 === 0) {
                for (let j = 0; j < length; j++) {
                    res += this.char;
                }
                console.log(res);
            }
        }
    }
    // left and right is symmetric, it is from 7 to 0, step 1;
    // mid is from 1, 3, 5, 7, ..., 11, 13, 15
    for4() {
        let times = 8;
        for (let i = 0; i < times; i++) {
            let res = "";
            for (let j = i; j < times - 1; j++) {
                res += " ";
            }
            let midLength = 2 * i + 1;
            for (let x = 1; x <= midLength; x++) {
                if (i === 0 || i === times - 1) res += this.char;
                else if (x === 1 || x === midLength) res+= this.char;
                else res += " ";
            }
            console.log(res);
        }
    }
}

var p = new PrintChar("A", 10);
p.for1();
console.log("===========================");
p.for2();
console.log("===========================");
p.for3();
console.log("===========================");
p.for4();